package com.jk.controller;

import com.jk.service.CouponService;
import com.jk.vo.CouponInfo;
import com.jk.vo.CouponUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @DeleteMapping("deleteCoupon")
    public String deleteCoupon(String id){

        couponService.deleteCoupon(id);

        return "ok";
    }
    @GetMapping("queryCoupon")
    @ResponseBody
    public List<Map> queryCoupon(CouponInfo couponInfo){
        List<Map> list = couponService.queryCoupon(couponInfo);
        System.out.println(list+"-----------------------------------------");
       /* Map map = new HashMap();
        map.put("dasdf","aaa");*/
        return list;
    }
    @GetMapping("queryUserCoupon")
    @ResponseBody
    public List<Map> queryUserCoupon(CouponInfo couponInfo){
        List<Map> list = couponService.queryUserCoupon(couponInfo);
        System.out.println(list+"-----------------------------------------");
       /* Map map = new HashMap();
        map.put("dasdf","aaa");*/
        return list;
    }
    @PostMapping("addCouponOfUser")
    @ResponseBody
    public Map addCouponOfUser(CouponUser couponUser,String couponId){
        /*添加当前时间*/
        couponUser.setCouponCreateTime(new Date());

        couponUser.setCouponStatus(1);

        int i =  couponService.addCouponOfUser(couponUser);

        Map map = new HashMap();

        map.put("mas",i);

        return  map;
    }
}
